import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

/** 状态定义 */

const store = new Vuex.Store({
  state: {
    memberId: '',
    customerId: '',
    phone: '',
    local: {},
    visitorId: '',
    enterpriseId: '',
    veekrayStatus: '', // -1：未注册  0: 免费  1：付费  2：已过期
    showBuyCard: '',
    nickName: '', // 登录用户昵称
    appInfo: {},
    cartBadge: 0,
    fastGoods: [],
    navList: [],
    isMethodInitData: {},
    categoryInfo: {},
    imToken: '',
    imSellerToList: [],
    imBuyerToList: [],
    imUnreadSeller: 0,
    imUnreadBuyer: 0,
    inMessage: '0',
    shareMemberId: null, // 用户保存分享者id信息
    previewImageFlag: false, // 商品详情sku是否预览图片
    isCommunityGroupExtraction: 0, // 是否社区团购提货点
    isHomeDelivery: 0, // 是否到家配送点
    isStoreExtraction: 0, // 是否门店自提点
    currentPickup: {},
    customerCommanderStatus: '', // 0: 顾客未成为团长  1：已是团长
    memberCommanderStatus: '', // 0: 店长未成为团长  1：已是团长
    memberCommanderEnable: '', // 0: 店长开启状态
    memberStoreState: '', // 0: 门店开启状态
    enterprisePhone: '',
    deliveryType: [],
    payMethod: null,
    cbFlag: null
  },
  mutations: {
    setMemberId: (state, memberId) => {
      state.memberId = memberId
    },
    setCustomerId: (state, customerId) => {
      state.customerId = customerId
    },
    setPhone: (state, phone) => {
      state.phone = phone
    },
    setPayMethod: (state, payMethod) => {
      state.payMethod = payMethod
    },
    setCbFlag: (state, cbFlag) => {
      state.cbFlag = cbFlag
    },
    setLocal: (state, local) => {
      state.local = local
    },
    setVisitorId: (state, visitorId) => {
      state.visitorId = visitorId
    },
    setEnterpriseId: (state, enterpriseId) => {
      state.enterpriseId = enterpriseId
    },
    setVeekrayStatus: (state, veekrayStatus) => {
      state.veekrayStatus = veekrayStatus
    },
    setMemberNature: (state, memberNature) => {
      state.memberNature = memberNature
    },
    setStoreCardFlag: (state, storeCardFlag) => {
      state.storeCardFlag = storeCardFlag
    },
    setShowBuyCard: (state, showBuyCard) => {
      state.showBuyCard = showBuyCard
    },
    setNickName: (state, nickName) => {
      state.nickName = nickName
    },
    setAppInfo: (state, appInfo) => {
      state.appInfo = appInfo
    },
    setCartBadge: (state, cartBadge) => {
      state.cartBadge = cartBadge
    },
    setFastGoods: (state, fastGoods) => {
      state.fastGoods = fastGoods
    },
    setNavList: (state, navList) => {
      state.navList = navList
    },
    setCategoryInfo: (state, categoryInfo) => {
      state.categoryInfo = categoryInfo
    },
    setIsCommunityGroupExtraction: (state, isCommunityGroupExtraction) => {
      state.isCommunityGroupExtraction = isCommunityGroupExtraction
    },
    setIsHomeDelivery: (state, isHomeDelivery) => {
      state.isHomeDelivery = isHomeDelivery
    },
    setIsStoreExtraction: (state, isStoreExtraction) => {
      state.isStoreExtraction = isStoreExtraction
    },
    setCurrentPickup: (state, currentPickup) => {
      state.currentPickup = currentPickup
    },
    setCustomerCommanderStatus: (state, customerCommanderStatus) => {
      state.customerCommanderStatus = customerCommanderStatus
    },
    setMemberCommanderStatus: (state, memberCommanderStatus) => {
      state.memberCommanderStatus = memberCommanderStatus
    },
    setMemberCommanderEnable: (state, memberCommanderEnable) => {
      state.memberCommanderEnable = memberCommanderEnable
    },
    setMemberStoreState: (state, memberStoreState) => {
      state.memberStoreState = memberStoreState
    },
    setEnterprisePhone: (state, enterprisePhone) => {
      state.enterprisePhone = enterprisePhone
    },
    setDeliveryType: (state, deliveryType) => {
      state.deliveryType = deliveryType
    },
    setImToken: (state, imToken) => {
      state.imToken = imToken
    },
    setImSellerToList: (state, imSellerToList) => {
      state.imSellerToList = imSellerToList
    },
    setImBuyerToList: (state, imBuyerToList) => {
      state.imBuyerToList = imBuyerToList
    },
    setImUnreadSeller: (state, imUnreadSeller) => {
      state.imUnreadSeller = imUnreadSeller
    },
    setImUnreadBuyer: (state, imUnreadBuyer) => {
      state.imUnreadBuyer = imUnreadBuyer
    },
    setInMessage: (state, inMessage) => {
      state.inMessage = inMessage
    },
    setMethodInitData: (state, pageMethod) => {
      if (pageMethod) {
        // 如果没有页面对象
        if (!state.isMethodInitData[pageMethod.page]) {
          state.isMethodInitData[pageMethod.page] = {}
        }
        // 如果没有传入方法，需要清除该页面所有方法的状态
        if (pageMethod.method) {
          state.isMethodInitData[pageMethod.page][pageMethod.method] = pageMethod.value
        } else {
          state.isMethodInitData[pageMethod.page] = {}
        }
      } else {
        // 清除所有页面的数据状态
        state.isMethodInitData = {}
      }
    },
    setShareMemberId: (state, shareMemberId) => {
      state.shareMemberId = shareMemberId
    },
    setPreviewImageFlag: (state, previewImageFlag) => {
      state.previewImageFlag = previewImageFlag
    }
  }
})

export default store
